<template>
    <div class="body" id="wekupButton">
    <div class="header"></div>
    <img
      src="../../assets/img/skin/title1.png"
      class="images"
      alt=""
    >
    <img
      @click="nav({goods_id:11403})"
      src="../../assets/img/skin/1@2x.png"
      class="imgHot"
      alt=""
    >
    <img
      @click="nav({goods_id:11405})"
      src="../../assets/img/skin/2@2x.png"
      class="imgHot"
      alt=""
    >
    <div class="box">
      <ul>
        <li>
          <img
            @click="nav({goods_id:11401})"
            src="../../assets/img/skin/three.png"
            alt=""
          >
        </li>
        <!-- <li>
          <img
            @click="nav({goods_id:11399})"
            src="../../assets/img/skin/five.png"
            alt=""
          >
        </li> -->
        <li>
          <img
            @click="nav({goods_id:11402})"
            src="../../assets/img/skin/six.png"
            alt=""
          >
        </li>
        <!-- <li>
          <img
            @click="nav({goods_id:11400})"
            src="../../assets/img/skin/ten.png"
            alt=""
          >
        </li> -->
      </ul>
    </div>

    <img
      @click="nav({goods_id:11396})"
      src="../../assets/img/skin/3@2x.png"
      class="imgHot"
      alt=""
    >
    <img
      @click="nav({goods_id:11398})"
      src="../../assets/img/skin/4@2x.png"
      class="imgHot"
      alt=""
    >
    <img
      @click="nav({goods_id:11406})"
      src="../../assets/img/skin/5@2x.png"
      class="imgHot"
      alt=""
    >
    <img
      src="../../assets/img/skin/title2.png"
      class="teoing"
      alt=""
    >
    <div class="add">
      <ul>
        <li
          v-for="item in list"
          :key="item.goods_id"
          @click="nav(item)"
        >
          <img
            :src="item.goods_img"
            class="img"
            alt=""
          >
          <div class="text">
            {{item.goods_name}}
          </div>
          <div class="money">
            ¥
            <span>{{item.active_price}}</span>
          </div>
        </li>
      </ul>
    </div>
    <div
      class="mone"
      @click="goto"
    >查看更多</div>
    <!-- 微信遮罩 -->
    <div
      @touchmove.prevent
      class="rigth"
      v-if="show"
    >
      <img
        src="../../assets/img/wei_20210307160153.png"
        alt=""
      >
    </div>
    <!-- 置顶 -->
    <div
      class="totop"
      id="totop"
      @click="backTop"
      v-show="btnFlag"
    >
    </div>
  </div>
</template>

<script>
import bridge from '../../js/js1'
import { index, Coupondev } from '@/api/index'
import { share } from '../../js/wechat'
import { getSystem, openApp, getUrlQuery, parseKeyValue } from '../../js/js'
export default {
  // 组件名称
  name: '',
  // 局部注册的组件
  components: {},
  // 组件参数 接收来自父组件的数据
  props: {},
  // 组件状态值
  data () {
    return {
      list: [],
      text: '',
      show: false,
      share: true,
      system: getSystem(),
      btnFlag: false,
    }
  },
  destroyed () {
    window.removeEventListener('scroll', this.scrollToTop);
  },
  // 计算属性
  computed: {},
  // 侦听器
  watch: {},
  // 生命周期钩子   注：没用到的钩子请自行删除
  /**
  * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
  */
  created () {
    this.isId()
    if (!this.system.yfd && !this.system.wechat) {
      if (this.system.iOS9 || this.system.android) {
        ULink([{
          id: 'usr1anivh5aa8uq6', // 后台生成的裂变活动LinkID
          data: {
            path: 'webview',
            webUrl: 'https://download.yuanfuda933.com/h5/other2.html#/skine',// 活动地址
            andUrl: 'https://download.yuanfuda933.com/h5/other2.html#/skine'// 活动地址
            // extraData: `{id:${this.id},uid:${this.uid}`,
            // extraData: {
            //   id: this.id,
            //   uid: this.uid,
            //   tid: this.tid
            // }
          }, /* 自定义参数，选填 */
          selector: '#wekupButton',
          useOpenInBrowerTips: 'default',
          proxyOpenDownload: function (defaultAction, LinkInstance) {
            window.location.href = LinkInstance.solution.downloadUrl
          }
        }])
      }
    } else {
      this.getToken(token => {
        this.$store.commit('setUser', token)
      })
    }
  },
  /**
  * el 被新创建的 vm.el 替换，并挂载到实例上去之后调用该钩子。
  * 如果 root 实例挂载了一个文档内元素，当 mounted 被调用时 vm.el 也在文档内。
  */
  mounted () {
    window.addEventListener('scroll', this.scrollToTop)
    share({
      title: '媛福达精选内蒙古羊!',
      desc: '抵挡不住的草原美食,先购卡再购物~',
      imgUrl: 'https://download.yuanfuda933.com/h5/images/skin.png',
      shareUrl: 'https://download.yuanfuda933.com/h5/other2.html#/skin',
    })
  },
  // 组件方法
  methods: {
    goto () {
      if (this.system.wechat) {
        this.show = true
        return false
      } else {
        this.show = false
      }
      window.location.href = 'yfd://yfdmall:8080/homePage?categoryId=360'
    },
    async isId () {
      try {
        const res = await index({
          id: 136
        })
        console.log(res.data.data);
        this.list = res.data.data.types[0].goods
      } catch (err) {
        console.log('错误');
      }
    },
    // 点击图片回到顶部方法，加计时器是为了过渡顺滑
    backTop () {
      const that = this
      let timer = setInterval(() => {
        let ispeed = Math.floor(-that.scrollTop / 5)
        document.documentElement.scrollTop = document.body.scrollTop = that.scrollTop + ispeed
        if (that.scrollTop === 0) {
          clearInterval(timer)
        }
      }, 16)
    },
    // 为了计算距离顶部的高度，当高度大于60显示回顶部图标，小于60则隐藏
    scrollToTop () {
      const that = this
      let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
      that.scrollTop = scrollTop
      // console.log(that.scrollTop);
      if (that.scrollTop > 800) {
        that.btnFlag = true
      } else {
        that.btnFlag = false
      }
    },
    // 跳转下载
    nav (item) {
      if (this.system.wechat) {
        this.show = true
        return false
      } else {
        this.show = false
      }
      if (!this.system.iOS9 && !this.system.android) {
        this.href('https://itunes.apple.com/cn/app/id1542709823?mt=8')
        return false
      }
      // if (this.system.iOS) this.href('https://itunes.apple.com/cn/app/id1542709823?mt=8')

    },
    href (uri, blank = true) {
      const a = document.createElement('a')
      a.style.display = 'none'
      a.href = uri
      if (blank) a.setAttribute('target', '_blank')
      document.body.appendChild(a)
      a.click()
      setTimeout(t => {
        document.body.removeChild(a)
      }, 0)
    },
  }
}
</script>

<style scoped lang="less">
.body {
  overflow: hidden;
  min-width: 320px;
  max-width: 750px;
  width: 10rem;
  background: #fffbef;
  margin: 0 auto;
  line-height: 1.5;
  font-family: Arial, Helvetica;
  .rigth {
    position: fixed;
    top: 0;
    z-index: 9999;
    width: 10rem;
    height: 30rem;
    background-color: #1e1e1e;
    opacity: 0.8;
  }
  .rigth img {
    width: 8rem;
    height: 4.4rem;
    float: right;
  }
  .header {
    width: 10rem;
    height: 9.546667rem;
    background: url("../../assets/img/skin/header.png") no-repeat;
    background-size: contain;
  }
  .teoing {
    width: 10rem;
    height: 1.173333rem;
    margin: 0.4rem auto;
  }
  .images {
    width: 10rem;
    height: 1.626667rem;
    margin: 0.4rem auto;
  }
  .imgHot {
    width: 10rem;
    height: 4.266667rem;
    margin: 1.066667rem auto;
  }
  .mone {
    width: 3.666667rem;
    height: 1.066667rem;
    font-size: 0.426667rem;
    text-align: center;
    color: #ffffff;
    border-radius: 0.4rem;
    background: #f5a100;
    font-weight: 600;
    line-height: 1.066667rem;
    margin: 0.266667rem auto;
  }
  .box {
    width: 10rem;
    height: 5.44rem;
    background-size: contain;
    background: url("../../assets/img/skin/back.png") no-repeat;
    margin: 0.4rem auto;
    display: flex;
    overflow-y: hidden;
    overflow-x: scroll;
    ul {
      display: flex;
      margin-top: 0.6rem;
      li {
        margin-left: 0.3rem;
        width: 3.306667rem;
        height: 4.133333rem;
        float: left;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
  .totop {
    position: fixed;
    width: 1.2rem; /* 40/16 */
    height: 1.2rem;
    border-radius: 1.25rem /* 20/16 */;
    opacity: 0.8;
    background: url("../../assets/ding.png") no-repeat;
    background-size: contain;
    box-shadow: 0 1px 5px 0 #e0e0e0;
    right: 0.125rem; /* 18/16 */
    bottom: 3rem; /* 64/16 */
    z-index: 1100;
    -webkit-transition: opacity 0.5s;
    transition: opacity 0.5s;
  }
  .add {
    width: 10rem;
    overflow: hidden;
    padding-top: 0.4rem;
    ul li {
      float: left;
      width: 4.56rem;
      height: 6.64rem;
      border-radius: 0.166667rem;
      background: #ffffff;
      margin-bottom: 0.133333rem;
      margin-left: 0.266667rem;
      .img {
        width: 3.493333rem;
        height: 3.173333rem;
        margin-top: 0.773333rem;
        margin-left: 0.506667rem;
      }
      .text {
        margin: 0.206667rem auto 0;
        width: 3.093333rem;
        height: 1.033333rem;
        font-weight: 600;
        font-size: 0.373333rem;
        color: #333333;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
      }
      .money {
        margin-left: 0.646667rem;
        // width: 1.333333rem;
        // height: 0.426667rem;
        font-size: 0.373333rem;
        color: #ff301e;
        span {
          font-size: 0.613333rem;
        }
      }
    }
  }
}
</style>
